package commons;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

/**
 * commons
 * User: 邱
 * Date: 2024/12/21 10:39
 * Description:
 * Version: V1.0
 */
public class EmailUtil {
    public static final String authorizeCode = "dpurfsuyaasibaea";
    public static final String smtpHost = "smtp.qq.com";
    public  static  final  String  sendEmail="1603139698@qq.com";
    public  static  final  String  sendName="智慧社区";

    /**
     * 协议
     */
    public static final String protocol = "smtp";

    //发送邮件代码
    public static boolean sendAuthCodeEmail(String email,String title,String context) {
        try {
            SimpleEmail mail = new SimpleEmail();
            mail.setHostName(smtpHost);//发送邮件的服务器
            mail.setAuthentication(sendEmail, authorizeCode);//刚刚记录的授权码，是开启SMTP的密码
            mail.setFrom(sendEmail);  //发送邮件的邮箱和发件人
            mail.setSSLOnConnect(true); //使用安全链接
            mail.addTo(email);//接收的邮箱
            //System.out.println("email"+email);
            mail.setSubject(title);//设置邮件的主题
            mail.setMsg(context);//设置邮件的内容
            mail.send();//发送
            return true;
        } catch (EmailException e) {
            e.printStackTrace();
            return false;
        }
    }
}
